#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
	int s1[100],s2[100];
	char c;
	int top1=-1,top2=-1;
	int n1,n2;
	int temp;
	scanf("%d %d",&n1,&n2);
	if(n1>n2){
		temp=n1;
		n1=n2;
		n2=temp;
	}
	while(1){
		getchar();
		scanf("%c",&c);
		if(c=='T')
			break;
		else if(c=='A'){
			scanf("%d",&temp);
			if(top1==n1-1&&top2!=-1){
				printf("full\n");
			}
			else if(top1==n1-1){
				while(top1>-1){
					s2[++top2]=s1[top1--];
				}
				s1[++top1]=temp;
			}
			else s1[++top1]=temp;
		}
		else if(c=='D'){
			if(top2!=-1){
				printf("%d\n",s2[top2--]);
			}
			else if(top2==-1&&top1!=-1){
				while(top1!=-1){
					s2[++top2]=s1[top1--];
				}
				printf("%d\n",s2[top2--]);
			}
			else{
				printf("empty");
			}
		}
	}
	return 0;
} 
